package query

import (
	"strings"

	"ssdevice/common/dto"
)

type SysDevSensorQuery struct {
	dto.Pagination `search:"-"`
	dto.OrderBy    `search:"-"`
	dto.UserInfo

	Id            string `form:"id"  search:"type:exact;column:id;table:sys_dev_sensor"`
	Sn            string `form:"sn"  search:"type:exact;column:sn;table:sys_dev_sensor"`
	ProductModel  string `form:"productModel"  search:"type:exact;column:product_model;table:sys_dev_sensor"`
	SchemaPath    string `form:"schemaPath" search:"-"`
	Sns           string `form:"sns" search:"-"`
	ProductModels string `form:"productModels" search:"-"`
	Keys          string `form:"keys" search:"-"`
	KeyNot        string `form:"keyNot" search:"-"`
	DeptId        string `form:"deptId" search:"-"`
	DeptIdNot     string `form:"deptIdNot" search:"-"`
	DevName       string `form:"devName" search:"-"`
	DevSn         string `form:"devSn" search:"-"`
	ProductNot    string `form:"productNot" search:"-"`
	Type          string `form:"type"  search:"type:exact;column:type;table:sys_dev_sensor"`
	Tag           string `form:"tag" search:"-"`
	AlarmStatus   *bool  `form:"alarmStatus"  search:"-"`
	OnlineStatus  string `form:"onlineStatus"  search:"-"`
	CustOrder     string `form:"custerOrder" search:"-" commit:"sn,key=asc;updateTime=desc"`

	SnIn           []string `search:"type:in;column:sn;table:sys_dev_sensor"`
	IdIn           []string `search:"type:in;column:id;table:sys_dev_sensor"`
	ProductModelIn []string `search:"type:in;column:product_model;table:sys_dev_sensor"`
	Key            string   `search:"type:exact;column:key;table:sys_dev_sensor"`
	KeyIn          []string `search:"type:in;column:key;table:sys_dev_sensor"`
	KeyNotIn       []string `search:"type:nin;column:key;table:sys_dev_sensor"`
	SnKeyConcatIn  []string `search:"type:concatin;column:sn,key;table:sys_dev_sensor"`
	SnKeyConcatNIn []string `search:"type:concatnin;column:sn,key;table:sys_dev_sensor"`
}

func (m *SysDevSensorQuery) GetNeedSearch() interface{} {
	if len(m.Sns) > 0 {
		m.SnIn = strings.Split(strings.ReplaceAll(m.Sns, " ", ""), ",")
	}
	if len(m.Keys) > 0 {
		m.KeyIn = strings.Split(strings.ReplaceAll(m.Keys, " ", ""), ",")
	}
	if len(m.KeyNot) > 0 {
		m.KeyNotIn = strings.Split(strings.ReplaceAll(m.KeyNot, " ", ""), ",")
	}
	if len(m.ProductModels) > 0 {
		m.ProductModelIn = strings.Split(strings.ReplaceAll(m.ProductModels, " ", ""), ",")
	}
	return *m
}

type SysDevProfileQuery struct {
	IdSn      string `form:"idSn"  search:"-"`
	Path      string `form:"path" search:"-"`
	ProductId string `form:"productId"  search:"-"`
}
